<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
	<title>流动市场摊位管理系统</title>
	<%@ include file="../inc.jsp" %>
	<style type="text/css">
	*{margin:0; padding:0;}
	ul{list-style-type:none; zoom:1;}
	ul li{float:center; margin:10px; _display:inline; border:0px solid #CCC;}
	ul li a img{width:48px; height:48px; border:0;display:block;margin:0px auto; vertical-align: middle;text-align:center;}
	ul li a.wenzi{line-height:20px; color:#666; display:block; text-align:center;}
	ul li a:hover{color:#F00;}
	#topDiv{
		background: url("../ali_icon/m_03.jpg") 0 0 no-repeat;
             background-size: 100% 100%;
		}
	</style>
</head>
<body class="easyui-layout">
	<!-- 上部   start -->
	<div data-options="region:'north',border:false"  style="height:120px;">
		<div style="width:80%;height:100%;margin-left:10%;" id="topDiv"></div>
		<div style="position: absolute; right: 0px; bottom: 0px; ">
			<span>${sessionScope.user.user_name}【${sessionScope.user.group_name}】</span>
			<a href="javascript:void(0);" class="easyui-menubutton" menu="#layout_north_zxMenu" iconCls="icon-back">注销</a>
		</div>
	
		<div id="layout_north_zxMenu" style="width: 100px; display: none;">
			<!-- <div onclick="loginAndRegDialog.dialog('open');">锁定窗口</div> -->
			<div class="menu-sep"></div>
			<div onclick="logout();">重新登录</div>
			<!-- <div onclick="logout(true);">退出系统</div> -->
		</div>
	</div>
	<!-- 上部   end -->
	<!-- 导航  start -->
	<div data-options="region:'west',split:false,title:'&nbsp;&nbsp;功能菜单',iconCls:'icon-tip'" style="width:160px;padding:0px;overflow:hidden;">
		<div id="nav_menu" class="easyui-accordion" fit="true" border="false" >
		</div>
		<script type="text/javascript">
			//动态生成操作菜单
		$(document).ready(function() {
			$.ajax({
				url:"${baseUrl}/admin/modules/showMenu",
				type:'post',
				async:false,
				dataType:'json',
				success:function(data){
					if(data.success==0)
					{
					    var pid=0;
					    var content="";
					    var title="";
					    var imgCls="";
						$.each(data.rows,function(i,item){
						    var content="";
						    if(item.children != null)
						    {
						        $.each(item.children,function(i,subItem){
	                                content = content + "<li><a href=\"javascript:addTab(\'"+subItem.name+"\',\'"+subItem.url+"\')\"><img src=\""+subItem.img+"\" width=\"32\" /></a><a class=\"wenzi\" href=\"javascript:addTab(\'"+subItem.name+"\',\'"+subItem.url+"\')\">"+subItem.name+"</a></li>";
						        });
						    }
						    $('#nav_menu').accordion('add', {
                                title: item.name,
                                content: '<div style="padding:0px;overflow:hidden"><ul id="ulSubMenu'+item.id+'">'+content+'</ul></div>',
                                selected: false,
                                iconCls: imgCls
                            }); 
						});
					}
					else
					{
						showErrMsg(data);
					}
				}
			});
		});
		</script>
		
	</div>
	<!-- 导航   end -->
	<!-- 底部   start -->
	<div data-options="region:'south',border:false" style="height:25px;padding:1px;">
		<div align="center">推荐分辨率1024*768+，使用谷歌内核浏览器可以获得更快的页面响应速度</div>
	</div>
	<!-- 底部   end -->
	<!-- 中间   start -->
	<div data-options="region:'center',title:'当前用户【${userName }】'">
		<div id="centerTabs" class="easyui-tabs" fit="true">
		 	 
		</div>
	</div>
	<div id="tabsMenu" class="easyui-menu" style="width:120px;">  
	    <div name="close">关闭</div>  
	    <div name="Other">关闭其他</div>  
	    <div name="All">关闭所有</div>
	  </div>  
	<script type="text/javascript" charset="UTF-8">
	function logout(flag)
	{
	    var msg;
	    if(flag)
	    {
	        msg = "你是否要退出系统？";
	    }
	    else
	    {
	        msg = "你是否要重新登录系统？";
	    }
	    $.messager.confirm("退出",msg,function(yesOrNo){
	        if(yesOrNo)
	        {
	            $.ajax("${baseUrl}/admin/logout",{
	                error:function(){
	                    $.messager.alert("提示","资源访问错误！");
	                },
	                success:function(data){
	                    var json = $.parseJSON(data);
	                    if(json.success==0)
	                    {
	                        if(flag)
	                        {
	                            window.opener = null;
	                            window.open('','_self');
	                            window.close();
	                        }
	                        else
	                        {
	                            window.parent.location.href="${baseUrl}/admin/login"
	                        }
	                    }
	                    else
	                    {
	                        showErrMsg(json);
	                    }
	                }
	            });
	        }
	    });
	}
	
			function addTab(title,url){
            	if ($('#centerTabs').tabs('exists', title))
            	{
                	var currtab = $('#centerTabs').tabs('getSelected');
                	var tab = $("#centerTabs").tabs("getTab", title);
                	if (currtab == tab) {
                    	var url=$(currtab.panel('options').content).attr('src');
                    	refreshTab(tab, url);
                	}
                	else {
                    	var tab = $("#centerTabs").tabs("select", title);
                    	var currtab = $('#centerTabs').tabs('getSelected');
                    	var url = $(currtab.panel('options').content).attr('src');
                    	refreshTab(tab, url);
                	}
            	}
            	else {
				     var content = '<iframe scrolling="auto" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
                	$('#centerTabs').tabs('add',
                    {
                        title: title,
                        content: content,
                        closable: true
                    });
            	}
        	}
			
			
			function refreshTab(obj,url)
			{
			     var refresh_tab = obj;
			     if (refresh_tab && refresh_tab.find('iframe').length > 0)
			        {
			           var _refresh_ifram = refresh_tab.find('iframe')[0];
			           _refresh_ifram.contentWindow.location.href = url;
			        } 
			}
			
	$(function () {
		 var content = '<iframe scrolling="auto" frameborder="0" src="${baseUrl}/admin/home" style="width:100%;height:100%;"></iframe>';
		$('#centerTabs').tabs('add',{
                    title: '首页',
                    content: content,
                    closable: false
                });
		
		    //绑定tabs的右键菜单
		    $("#centerTabs").tabs({
		        onContextMenu : function (e, title) {
		            e.preventDefault();
		            $('#tabsMenu').menu('show', {
		                left : e.pageX,
		                top : e.pageY
		            }).data("tabTitle", title);
		        }
		    });

		    //实例化menu的onClick事件
		    $("#tabsMenu").menu({
		        onClick : function (item) {
		            CloseTab(this, item.name);
		        }
		    });

		    //几个关闭事件的实现
		    function CloseTab(menu, type) {
		        var curTabTitle = $(menu).data("tabTitle");
		        var tabs = $("#centerTabs");
		        
		        if (type === "close") {
		            tabs.tabs("close", curTabTitle);
		            return;
		        }
		        
		        var allTabs = tabs.tabs("tabs");
		        var closeTabsTitle = [];
		        
		        $.each(allTabs, function () {
		            var opt = $(this).panel("options");
		            if (opt.closable && opt.title != curTabTitle && type === "Other") {
		                closeTabsTitle.push(opt.title);
		            } else if (opt.closable && type === "All") {
		                closeTabsTitle.push(opt.title);
		            }
		        });
		        for (var i = 0; i < closeTabsTitle.length; i++) {
		            tabs.tabs("close", closeTabsTitle[i]);
		        }
		    }
	});
	</script>
	<!-- 中间   end -->
</body>
</html>